package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.EnterpriseInvoiceInfoEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.util.StringUtil;

/**
*@version 创建时间：2017年8月1日 下午3:12:06
*@author wenwenlong
*类说明
*/

@Implements(EnterpriseInvoiceInfoService.class)
public class EnterpriseInvoiceInfoServiceImpl implements EnterpriseInvoiceInfoService {

	@Override
	public void createEnterpriseInvoiceInfo(EnterpriseInvoiceInfoEntity entity) {
		PersistUtil.insert(entity);
	}

	@Override
	public void updateEnterpriseInvoiceInfo(EnterpriseInvoiceInfoEntity entity) {
		PersistUtil.update(entity);
	}

	@Override
	public EnterpriseInvoiceInfoEntity inquireEnterpriseInvoiceInfo(Long accountId, String invoiceEnterpriseName) {
		DetachedCriteria criteria = DetachedCriteria.forClass(EnterpriseInvoiceInfoEntity.class);
		criteria.add(Restrictions.eq("accountId", accountId));
		if (StringUtil.isNotBlank(invoiceEnterpriseName)) {
			criteria.add(Restrictions.eq("invoiceEnterpriseName", invoiceEnterpriseName));
		}
		List<EnterpriseInvoiceInfoEntity> list = PersistUtil.get(criteria);
		if (list == null || list.size() == 0) {
			return null;
		} else {
			return list.get(0);
		}
	}

	@Override
	public PageList<EnterpriseInvoiceInfoEntity> inquireEnterpriseInvoiceInfoPageList(Long accountId, String invoiceEnterpriseName,
			PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(EnterpriseInvoiceInfoEntity.class);
		if (StringUtil.isNotBlank(invoiceEnterpriseName)) {
			criteria.add(Restrictions.like("invoiceEnterpriseName", "%" + invoiceEnterpriseName + "%"));
		}
		criteria.add(Restrictions.eq("accountId", accountId));
		return PersistUtil.get(criteria, page);
	}
}
